<?php
require_once("../../../config.inc.php");
require_once("../../../app/_inc/include.php");

if(!isset($_REQUEST["mod"])){
	$url = $_SESSION[USEROBJ]->getHistory(-1, true)."&msg=".urlencode(_t("variabile 'mod' non passata")); 
	serverRedir($url);
}
if(!isset($_REQUEST["menu_page"])){
	$url = $_SESSION[USEROBJ]->getHistory(-1, true)."&msg=".urlencode(_t("variabile 'menu_page' non passata")); 
	serverRedir($url);
}
if(!isset($_REQUEST["menu_group"])){
	$url = $_SESSION[USEROBJ]->getHistory(-1, true)."&msg=".urlencode(_t("variabile 'menu_group' non passata")); 
	serverRedir($url);
}

$errMsg = sxREQ('msg');

if(sxREQ('del') == "yes"){
	$errMsg .= menuPageGroupDel();
}
$module = sxREQ('mod');
$menuPage = sxREQ('menu_page');
$menuGroup = $newGroup = sxREQ('menu_group');
$sSQL = "SELECT mg.*, m.description AS mdes, mp.description AS pdes FROM menu_group mg " .
		" INNER JOIN module m ON m.module = mg.module " .
		" INNER JOIN menu_page mp ON mp.module = mg.module AND mp.menu_page = mg.menu_page" .
		" WHERE mg.module = '$module' AND mg.menu_page = '$menuPage' AND mg.menu_group = '$menuGroup' ";
$objSDAO->query($sSQL,"mod");
if (!$row=$objSDAO->fetch("mod")) {
	$url = $_SESSION[USEROBJ]->getHistory(-1, true)."&msg=".
		urlencode(_t("gruppo voci men@ '%s'inesistente",$module.'.'.$menuPage.'.'.$menuGroup)); 
	serverRedir($url);
}
$description = $row['description'];
$note = $row['note'];
$sequence = $row['sequence'];
$flagDisplay = $row['flag_display'];

//output HTML
$aOpz = array("tit2"=>_t("Visualizza gruppo voci pagina men@"));
echo(headerHTML($aOpz));
?>
<script language="JavaScript" type="text/javascript">
	function confGroupDel(){
		try{
			if (confirm('<?=_t('Confermi la cancellreqtype del gruppo voci men@ ?');?>')) {
				document.location.href='menuPageGroupView.php?<?="del=yes&mod=$module&menu_page=$menuPage&menu_group=$menuGroup&xsn=".XSN?>';
			}
		}catch(e){
			raiseError(e.description, "del/menuPageGroupView");
		}			
	}
</script>
  
<?php
echo(bodyHTML($aOpz));
echo("<table width=\"100%\" cellpadding=\"03\" cellspacing=\"0\">\n<tr>\n<td>\n");
//output comandi
$aCmd = array(
					"modmg"=>array("pag"=>"menuPageGroupMod.php?mod=$module&menu_page=$menuPage&menu_group=$menuGroup",
										"title"=>_t("modifica gruppo voci men@"),
										"text"=>_t("modifica")
										),
					"delmg"=>array("pag"=>"javascript:confGroupDel()",
										"title"=>_t("elimina eliminreqtype gruppo voci men@"),
										"text"=>_t("elimina")
										),
					"back"=>array("pag"=>$objUser->getHistory(-1,false),
										"title"=>$objUser->getHistoryText(-1),
										"text"=>$objUser->getHistoryText(-1)
										)
					);
echo(commandsHTML($aCmd));	
echo("<table class=\"tabl01\" width=\"100%\" cellpadding=\"3\" cellspacing=\"2\" border='0'>\n");
echo("<tr>" .
			"<td class=\"titl01\" width=\"20%\" colspan='4'>"._t("Modulo").": $module - ".''."</td>" .
		"</tr>\n");
echo("<tr>" .
			"<td class=\"labl01\" width='20%'>"._t("codice")."</td>" .
			"<td class=\"text01\" width='10%'>$menuGroup</td>" .
			"<td class=\"labl01\" width='10%'>"._t("sequenza")."</td>" .
			"<td class=\"text01\" width='60%'>$sequence</td>" .
		"</tr>\n");
echo("<tr>" .
			"<td class=\"labl01\">"._t("description")."</td>" .
			"<td class=\"text01\" colspan='3'>$description</td>" .
		"</tr>\n");
echo("<tr>" .
			"<td class=\"labl01\">"._t("note")."</td>" .
			"<td class=\"text01\" colspan='3'><pre class=\"text01\" >".sxWW(sxHE($note))."</pre></td>" .
		"</tr>\n");
echo("<tr>" .
			"<td class=\"labl01\">"._t("Visualizza")."</td>" .
			"<td class=\"text01\" colspan='3'>" .(($flagDisplay=='Y')?_t('yes'):_t('no'))."</td>" .
		"</tr>\n");
echo("</table>");

echo(commandsHTML($aCmd));
echo("<div id=\"messArea\" class=\"mess01\">$errMsg</div>");
echo("</td>\n</tr>\n</table>\n");
echo(footerHTML());

function menuPageGroupDel(){
	global $objSDAO;
	$errMsg = "";
	//controlli integrit@ ref.
	if (sxREQUEST('menu_group') != sxREQUEST('new_group')) {
		$sSQL = "SELECT count(*) as num FROM menu_line " .
				" WHERE menu_line LIKE '".sxRAS("mod").".".sxRAS("menu_page").".%' " .
					" AND menu_group = '".sxRAS("menu_group")."'";
		$objSDAO->query($sSQL,"mod");
		$row = $objSDAO->fetch("mod");
		if($row["num"] != 0)
			$errMsg .= _t("Il gruppo voci @ referenziato in %s voci men@.<br>",$row["num"]);
	}
	if($errMsg != ""){ return $errMsg; }
	$sSQL = "DELETE FROM menu_group " .
			   "WHERE module='".sxRAS("mod")."' " .
				" AND menu_page = '".sxRAS("menu_page")."'".
				" AND menu_group = '".sxRAS("menu_group")."'";
	$objSDAO->query($sSQL,"ins");
	logRecord("300", _t("Elininato gruppo voci men@ '".sxREQUEST('mod').
		"/".sxREQUEST('menu_page')."/".sxREQUEST('menu_group')."'"));
	$url = $_SESSION[USEROBJ]->getHistory(-1, true);
	serverRedir($url);
	exit;
}

?>
